#include "Component.h"
#include "Transform.h"
#include "Renderer.h"
#include "Scene.h"
namespace ManchyGL
{
	Scene::Scene()
	{
		_gameObjects = new vector<GameObject*>();
	}

	Scene::~Scene()
	{
		if (NULL != _gameObjects)
		{
			for (vector<GameObject*>::iterator iter = _gameObjects->begin(); iter != _gameObjects->end(); ++iter)
				delete (*iter);
			delete _gameObjects;
			_gameObjects = NULL;
		}
	}

	GameObject* Scene::NewGameObject(const char* name)
	{
		GameObject* go = new GameObject(name);
		go->AddComponent(ComponentType_Transform, new Transform());
		go->AddComponent(ComponentType_Renderer, new Renderer());
		_gameObjects->push_back(go);
		return go;
	}

	GameObject* Scene::GetGameObject(const char* name)
	{
		for (vector<GameObject*>::iterator iter = _gameObjects->begin(); iter != _gameObjects->end(); ++iter)
		{
			if ((*iter)->GetName() == name)
				return (*iter);
		}
		return NULL;
	}

	int Scene::GetCount()
	{
		return _gameObjects->size();
	}

	GameObject* Scene::GetGameObject(int index)
	{
		return (*_gameObjects)[index];
	}
}